package com.jic.member.controller.manage;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.member.common.util.BeanUtil;
import com.jic.member.entity.MemMemberCustomLabel;
import com.jic.member.enums.EXCEPTION;
import com.jic.member.request.MemMemberCustomLabelRequest;
import com.jic.member.response.MemMemberCustomLabelResponse;
import com.jic.member.service.MemMemberCustomLabelService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author
 */

@ApiOperation(value = "自定义标签controller")
@Slf4j
@RestController
@RequestMapping("/memMemberCustomLabe")
public class MemMemberCustomLabelController {

    @Autowired
    private MemMemberCustomLabelService memMemberCustomLabelService;

    @ApiOperation(value = "获取自定义标签列表")
    @ResponseBody
    @RequestMapping(value = "/queryList")
    public RestResult<PageResult<MemMemberCustomLabelResponse>> queryList(@RequestBody MemMemberCustomLabelRequest form) {
        log.info("query 获取自定义标签列表 param is ,{}",form);
        return memMemberCustomLabelService.queryPage(form);
    }

    @ApiOperation("修改列表")
    @RequestMapping("update")
    public RestResult update(@RequestBody MemMemberCustomLabelRequest param){
        RestResult result =new  RestResult();
        result.setData(memMemberCustomLabelService.update(param));
        result.setCode(EXCEPTION.SUCCESS.getName());
        result.setMsg(EXCEPTION.SUCCESS.getDesc());
        return result;
    }

    @ApiOperation(value = "获取自定义标签列表不分页")
    @ResponseBody
    @RequestMapping(value = "/queryLableList")
    public RestResult<MemMemberCustomLabel> queryLableList(@RequestBody MemMemberCustomLabelRequest form) {
        log.info("query 获取自定义标签列表 param is ,{}",form);
        RestResult result =new  RestResult();
        MemMemberCustomLabel memMemberCustomLabel = BeanUtil.copy(form, MemMemberCustomLabel.class);
        result.setData(memMemberCustomLabelService.query(memMemberCustomLabel));
        result.setCode(EXCEPTION.SUCCESS.getName());
        result.setMsg(EXCEPTION.SUCCESS.getDesc());
        return result;
    }

    @ApiOperation("新增自定义标签")
    @RequestMapping("addMemMemberCustomLabel")
    public RestResult addMemMemberCustomLabel(@RequestBody MemMemberCustomLabelRequest request){
        RestResult  restResult = new RestResult();
        restResult= memMemberCustomLabelService.insert(request);
        return restResult;
    }

    @ApiOperation("自定义积分规则上线")
    @RequestMapping("integralOnline")
    public RestResult integralOnline(@RequestBody MemMemberCustomLabelRequest request){

        RestResult  restResult = new RestResult();
        final long insert = memMemberCustomLabelService.update(request);
        if(insert > 0){
            restResult.setCode(EXCEPTION.SUCCESS.getName());
            restResult.setMsg(EXCEPTION.SUCCESS.getDesc());
            restResult.setData(insert);
        }else {
            restResult.setCode(EXCEPTION.FAIL.getName());
        }
        return restResult;
    }
    @ApiOperation("自定义规则删除")
    @RequestMapping("delCustomizeIntegralRule")
    public RestResult delCustomizeIntegralRule(@RequestBody MemMemberCustomLabelRequest request){
        RestResult restResult = memMemberCustomLabelService.deleteInfo(request);
        return restResult;
    }
    @ApiOperation("自定义积分规则开放给商家")
    @RequestMapping("openIntegralToMerchant")
    public RestResult  openIntegralToMerchant(@RequestBody MemMemberCustomLabelRequest request){
        RestResult restResult =new RestResult();
        final long update = memMemberCustomLabelService.update(request);
        if(update > 0){
            restResult.setCode(EXCEPTION.SUCCESS.getName());
            restResult.setMsg(EXCEPTION.SUCCESS.getDesc());
            restResult.setData(update);
        }
        return restResult;
    }

}
